package 剑指offer;

import org.junit.Test;

import java.util.LinkedList;

public class 翻转单词顺序 {
    public String reverseWords(String s) {
        String[] s1 = s.trim().split(" ");
        StringBuilder builder = new StringBuilder();
        for (int i = s1.length-1; i >0 ; i--) {
            if (s1[i].equals(""))
                continue;
            builder.append(s1[i].trim()).append(" ");
        }
        builder.append(s1[0].trim());
        return builder.toString();
    }
    @Test
    public void test(){
        String s=" abc def  qwe";
        String[] s1 = s.trim().split(" ");
        System.out.println(s1[2].length());
        for (String s2 : s1) {
            System.out.println(s2);
        }
    }
}
